﻿using Base.Structure.Application.Interfaces;
using Base.Structure.Application.Services;
using Base.Structure.Cache;
using Base.Structure.Infrastructure.Repositories;
using Base.Structure.MessageQueue;
using Microsoft.OpenApi.Models;

namespace Base.Structure.WebApi
{
    public static class DependencyInjection
    {
        public static void AddApplicationServices(this IServiceCollection services)
        {
            // 注册业务逻辑层（应用服务）
            services.AddScoped<IUserService, UserService>();
        }

        public static void AddInfrastructureServices(this IServiceCollection services)
        {
            // 注册数据访问层（仓储）
            services.AddScoped<IUserRepository, UserRepository>();
        }

        public static void AddCacheServices(this IServiceCollection services)
        {
            // 注册缓存服务
            services.AddScoped<ICacheHelper, CacheHelper>();
        }

        public static void AddMessageQueueServices(this IServiceCollection services)
        {
            // 注册消息队列服务
            services.AddScoped<IMessageProducer, MessageProducer>();
            services.AddScoped<IMessageConsumer, MessageConsumer>();
        }

        public static void AddSwaggerServices(this IServiceCollection services)
        {
            // 注册Swagger服务
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "Base.Structure.WebApi", Version = "v1" });
            });
        }
    }
}
